
package presentacion;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.Arrays;
import javax.swing.JOptionPane;


/**
 *
 * @author WebVVE
 */
public class Login extends javax.swing.JFrame {
    
    
    /** Creates new form Login */
    public Login() {
        initComponents();
        this.rootPane.setDefaultButton(btn_Acceder);
        btn_Acceder.addKeyListener(new PresionarTecla());
        setLocationRelativeTo(null); //Situa la ventana al centro de la pantalla
        this.mensajesAyuda();
    }
    
    private void mensajesAyuda(){
        this.txt_Usuario.setToolTipText("Digite el nombre del Usuario del Sistema. Debe ser solo de letras");
        this.txt_Contraseña.setToolTipText("Digite la contraseña del respectivo Usuario. Puede ser numeros y letras");
    }
    
    /**
     * 
     */
    public class PresionarTecla extends KeyAdapter {
 
        @Override
      public void keyPressed(KeyEvent ke) {
          if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
              btn_AccederActionPerformed(null);
          }
      }
}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lb_Usuario = new javax.swing.JLabel();
        txt_Usuario = new javax.swing.JTextField();
        lb_Contraseña = new javax.swing.JLabel();
        btn_Acceder = new javax.swing.JButton();
        txt_Contraseña = new javax.swing.JPasswordField();
        jLabel3 = new javax.swing.JLabel();
        img_Megalaboratorio = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SMEI");

        lb_Usuario.setText("Nombre de Usuario:");

        lb_Contraseña.setText("Contraseña:");

        btn_Acceder.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentacion/imagenes/Aceptar.png"))); // NOI18N
        btn_Acceder.setText("Acceder");
        btn_Acceder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_AccederActionPerformed(evt);
            }
        });

        img_Megalaboratorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentacion/imagenes/DSC04573 (WinCE).JPG"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lb_Contraseña)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(txt_Usuario, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(lb_Usuario)
                                        .addComponent(txt_Contraseña, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)))
                                .addGap(67, 67, 67))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btn_Acceder)
                        .addGap(80, 80, 80)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(img_Megalaboratorio))
                .addGap(23, 23, 23))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(img_Megalaboratorio)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(9, 9, 9)
                        .addComponent(lb_Usuario)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txt_Usuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(lb_Contraseña)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txt_Contraseña, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btn_Acceder)))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btn_AccederActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_AccederActionPerformed
    char[] clave = {'a', 'd', 'm', 'i', 'n'};
    char[] clave2 = {'a', 's', 'i', 's'};
    if(!this.txt_Usuario.getText().equals("") && this.txt_Contraseña.getPassword() != null){
        if(this.txt_Usuario.getText().equals("administrador")){
            if( Arrays.equals(this.txt_Contraseña.getPassword(), clave)){
                MenuPrincipal menu = new MenuPrincipal(1);
                this.dispose();
                menu.setVisible(true);
            }else
                JOptionPane.showMessageDialog(rootPane, "Usuario y/o contraseña incorrectos");
        }else if(this.txt_Usuario.getText().equals("asistente")){
            if( Arrays.equals(this.txt_Contraseña.getPassword(), clave2)){
                MenuPrincipal menu = new MenuPrincipal(2);
                this.dispose();
                menu.setVisible(true);
            }else
                JOptionPane.showMessageDialog(rootPane, "Usuario y/o contraseña incorrectos");
        }else
            JOptionPane.showMessageDialog(rootPane, "Usuario y/o contraseña incorrectos");
    }else
        JOptionPane.showMessageDialog(rootPane, "Usuario y/o contraseña incorrectos");
}//GEN-LAST:event_btn_AccederActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Acceder;
    private javax.swing.JLabel img_Megalaboratorio;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel lb_Contraseña;
    private javax.swing.JLabel lb_Usuario;
    private javax.swing.JPasswordField txt_Contraseña;
    private javax.swing.JTextField txt_Usuario;
    // End of variables declaration//GEN-END:variables
}
